const User = require('./User');
const Weather = require('./Weather');
const Favorite = require('./Favorite');
const Forecast = require('./Forecast');
const Warning = require('./Warning');

// 建立关联关系
// User <-> Favorite
User.hasMany(Favorite, { foreignKey: 'userId', onDelete: 'CASCADE' });
Favorite.belongsTo(User, { foreignKey: 'userId' });

// Weather <-> Forecast
Weather.hasMany(Forecast, { foreignKey: 'weatherId', as: 'forecasts', onDelete: 'CASCADE' });
Forecast.belongsTo(Weather, { foreignKey: 'weatherId' });

// User <-> Warning
User.hasMany(Warning, { foreignKey: 'userId', onDelete: 'CASCADE' });
Warning.belongsTo(User, { foreignKey: 'userId' });

module.exports = {
  User,
  Weather,
  Favorite,
  Forecast,
  Warning
}; 